from common.Ulitys import ForumDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
class PostDetails:
    driver=""
    url=""
    def __init__(self):
        self.driver=ForumDriver.driver
        # self.url="http://127.0.0.1:9580/index.html"
        # self.driver.get(self.url)
        
    def PostDetailsUITest(self):
        # 点击C++板块帖子
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(3) > a").click()
        # 等待帖子加载，点击
        WebDriverWait(self.driver,5).until(
            EC.visibility_of_all_elements_located((By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a"))
        )
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a").click()
        # 进入帖子详情页面
        time.sleep(2)
        # 检查元素     
        self.driver.find_element(By.CSS_SELECTOR,"#details_article_content_title") # 标题
        self.driver.find_element(By.CSS_SELECTOR,"#details_article_createTime") # 发布时间
        self.driver.find_element(By.CSS_SELECTOR,"#details_article_content") # 内容
        self.driver.find_element(By.CSS_SELECTOR,"#article_details_author_name") # 作者
        self.driver.find_element(By.CSS_SELECTOR,"#details_btn_like_count") # 点赞按钮
        self.driver.find_element(By.CSS_SELECTOR,"#details_btn_article_reply") # 回复按钮
        self.driver.find_element(By.CSS_SELECTOR,"#article_details_reply > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre") # 回复框
        ForumDriver.getScreenShot() # 截图
        
    def PostDetailsFuncTest(self):
        # 点赞
        self.driver.find_element(By.CSS_SELECTOR,"#details_btn_like_count").click()
        time.sleep(1)
        text=self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert text=="成功"
        ForumDriver.getScreenShot()
        self.driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")
        time.sleep(1)
        # 不编辑内容点击回复
        btn=self.driver.find_element(By.CSS_SELECTOR,"#details_btn_article_reply")
        btn.click()
        time.sleep(1)
        ForumDriver.getScreenShot()  ## 截图验证， 获取不到“请输入回复内容”文本提示
        # 评论发布
        self.driver.find_element(By.CSS_SELECTOR,"#article_details_reply > div.editormd-toolbar > div > ul > li:nth-child(6) > a").click()
        # 点击发布
        time.sleep(1)
        btn.click() 
        time.sleep(1)
        ForumDriver.getScreenShot()  # 截图验证，获取不到“回复成功”文本提示
        # 回到顶部
        self.driver.execute_script("var q=document.documentElement.scrollTop=0")
        time.sleep(1)
        
        
        
        
        
        
        
